<?
	require ('../businessObjects/accountableTransaction.php');
	require ('../businessObjects/enterprise.php');
?>
<script language="javascript" type="text/javascript">
$(document).ready(function(){	   
/*Apply default button style. */		
		$('#btnSubmit').button();		
		$('.gridButton').button();		
		$( "#txtstartdate" ).datepicker();
		$("#txtenddate").datepicker();
		$('#form1').validate({
			rules:{
				txtIncomeID: {number:true}, 
				txtstartdate: {required:true, date:true}, 
				txtenddate: {required:true, date:true}, 
				txtminamount: {number:true}, 
				txtmaxamount: {number:true}
			},
			messages:{				
				txtstartdate: {date:'Please enter a valid date, using the format mm/dd/yyyy'},
				txtenddate: {date:'Please enter a valid date, using the format mm/dd/yyyy'}				
			}			
		});
	});    
</script>

<div class="workspace_panel">
	<div class="workspace_panel_row">
	<div class="workspace_panel_cell">
		<div style="display:table; width:100%;">
			<div style="display:table-row">
				<div style="display:table-cell; width:20%;"><h1>Incomes Tracking</h1></div>
				<div style="display:table-cell; text-align:right;">					
					<a href="<?=$go_back_menu?>" class="gridButton">Go Back </a>					
					<a href="?<?=$_SERVER['QUERY_STRING']?>&activity=add" class="gridButton">Add an Income </a>						
				</div>
			</div>
		</div>			
	</div>
	</div>	
	<div class="workspace_panel_row">
		<div class="workspace_panel_cell">
		<h2> Search for Incomes </h2>
		<p> Use the fields to enter a search criteria.</p>
        <form id="form1" action="?<?=$_SERVER['QUERY_STRING']?>" method="post">
        <div class="frmContainer" style="width:50%;">
            <div class="frmRow">
                <div class="frmLabelCell">Enterprise</div>
                <div class="frmContentCell">
						<select name="lstEnterprise" id="lstEnterprise" class="controlListBox">							
							<?php 
								$enterprise = new enterprise();		
								$enterprise->getEnterprise('');							
								while($row = mysqli_fetch_array($enterprise->resultSet()))
								{
							?>
							<option value="<?=$row['enterpriseID']?>"> <?=$row['enterpriseName']?> </option>
							<?}?>
						</select> 

				</div>							
            </div>
        	<div class="frmRow">
	        	<div class="frmLabelCell">Transaction ID</div>
				<div class="frmContentCell"><input type="textbox" id="txtIncomeID" name="txtIncomeID" class="controlTextBoxDefault" /></div>
			</div>
	        <div class="frmRow">
		        <div class="frmLabelCell">Start Date (mm/dd/yyyy)</div>
		        <div class="frmContentCell"><input type="textbox" id="txtstartdate" name="txtstartdate" class="controlTextBoxDefault" /></div>
	        </div>
	        <div class="frmRow">
		        <div class="frmLabelCell">End Date (mm/dd/yyyy)</div>
		        <div class="frmContentCell"><input type="textbox" id="txtenddate" name="txtenddate" class="controlTextBoxDefault" /></div>
	        </div>
	        <div class="frmRow">
		        <div class="frmLabelCell">Min Amount GTQ</div>
		        <div class="frmContentCell"><input type="textbox" id="txtminamount" name="txtminamount" class="controlTextBoxDefault" /></div>
	        </div>
			<div class="frmRow">
		        <div class="frmLabelCell">Max Amount GTQ</div>
				<div class="frmContentCell"><input type="textbox" id="txtmaxamount" name="txtmaxamount" class="controlTextBoxDefault"  /></div>
	        </div>
			<div class="frmRow">
		        <div class="frmLabelCell">Category Name</div>
		        <div class="frmContentCell"><input type="textbox" id="txtCategory" name="txtCategory" class="controlTextBoxDefault"  /></div>
	        </div>
	        <div class="frmRow">
		        <div class="frmLabelCell">Tracking Notes</div>
		        <div class="frmContentCell"><input type="textbox" id="txtTrackingNotes" name="txtTrackingNotes" class="controlTextBoxDefault" /></div>
	        </div>
            <div class="frmRow">
            	<div class="frmContentCell">&nbsp;</div>
                <div class="frmContentCell">					
                	<input type="submit" id="btnSubmit" name="btnSubmit" value="Search" />
					<input type="hidden" id="hddSeed" name="hddSeed" value="seed" />
				</div>
            </div>
	   	</div>						
		</form>
	</div>		
	</div>
    <div class="workspace_panel_row">
    	<div class="workspace_panel_cell">
        	<?php
				if ($_POST['hddSeed'] == 'seed'){
					$sysObj = new sysFunctions();
					$searchObject = new income();
					$searchObject->searchIncomes(($_POST['lstEnterprise'] != 'default')? $_POST['lstEnterprise'] : '',
													$_POST['txtIncomeID'],
													$_POST['txtstartdate'],$_POST['txtenddate'],
													$_POST['txtminamount'],$_POST['txtmaxamount'],
													$_POST['txtCategory'],$_POST['txtTrackingNotes']);									
			?>
				<p>Search results: <?=mysqli_num_rows($searchObject->resultSet());?></p>
            	<table class="resultsGrid">
                	<tr>
                    	<th>&nbsp;</th>
						<th>Enterprise</th>
                    	<th>Id</th>
                        <th>Date</th>
                        <th>Amount GTQ</th>
                        <th>Amount USD</th>
                        <th>exchangeRate</th>
                        <th>Category</th>
                        <th>Tracking Notes</th>
						<th></th>
                    </tr>
                    <?php while($row = mysqli_fetch_array($searchObject->resultSet())){ ?>
					<tr>
	                    <td style="width:5%;"><a href="?<?=$_SERVER['QUERY_STRING']?>&activity=del&ref=<?=$sysObj->encryptData($row['trnId']);?>" class="gridButton">Delete</a></td>
                    	<td><?=$row['enterpriseName']?></td>
						<td><?=$row['trnId']?></td>
                        <td><?=date("Y-m-d",strtotime($row['trnDate']));?></td>
                        <td><?=$row['amount_GTQ']?></td>
                        <td><?=$row['amount_USD']?></td>
                        <td><?=$row['exchangeRate']?></td>
                        <td><?=$row['CategoryName'];?></td>
                        <td style="text-align:left;"><?=$sysObj->smallSentence($row['trackingNotes'],4);?></td>
						<td>
							<? if ($row['attachedFile']!=''){?>								
								<a href="<?=sysConfigParameters::sysDocumentRoot.$row['attachedFile']?>" target="_blank"><img src="images/filedoc.png" width="16"></a>
							<? }?>
						</td>
                    </tr>		
					<?php }?>
                </table>
            <? } ?>
        </div>
    </div>
</div>
